package com.itheima.service.impl;

import com.itheima.dao.RoleModuleDao;
import com.itheima.service.RoleModuleService;
import com.itheima.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class RoleModuleServiceImpl implements RoleModuleService {
    @Override
    public void updateRoleModule(String roleId, List<String> list) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RoleModuleDao mapper = sqlSession.getMapper(RoleModuleDao.class);
        mapper.delete(roleId);
        for (String moduleId : list) {
            mapper.add(moduleId,roleId);
        }
    }

    @Override
    public List<String > findRoleIdByModule(String roleId) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        RoleModuleDao mapper = sqlSession.getMapper(RoleModuleDao.class);
       List<String > list =  mapper.findRoleIdByModule(roleId);
        return list;
    }
}
